package AdminController.AdminAce;


import java.io.IOException;
import java.io.PrintWriter;
import java.util.GregorianCalendar;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import Connect.connector;


public class AdminAce extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
   
    public AdminAce() {
        super();
       
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		System.out.println("*****차트파트*****");
		
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		response.setContentType("text/html; charset=UTF-8");
		
		String action_code = request.getParameter("action_code");
		
		AdminAceBean aAbean =  new AdminAceBean();
		AdminAceptDAO aAdao = new AdminAceptDAO();
		AdminAceBean[] aAbeanB = null;
		
		int year = 0;
		
		RequestDispatcher view = null;
		PrintWriter out =response.getWriter();
		
		GregorianCalendar Nstart;
		GregorianCalendar Nend;
		
		if(action_code.equals("memList")){
			System.out.println("월별 회원수 차트");
			String numMode = request.getParameter("num");
			System.out.println(request.getParameter("num"));
			int start = numMode != null ? Integer.parseInt(numMode) : -1;
			
			switch(start){
				
			case 1:
				System.out.println("*****접수통계 가기*****");
				
				request.setAttribute("page","/Manage/Man_Chart");
				view = request.getRequestDispatcher("/Main/admin/Ad_Main.jsp");
				view.forward(request, response);
				break;
			case 2:
				System.out.println("*****차트목록 만들어보세!!*****");
				year = Integer.parseInt(request.getParameter("year"));
				
				System.out.println("선택 년도:"+year);
				System.out.println("선택 종류:"+request.getParameter("list"));
				
				Nstart = new GregorianCalendar(year, 0, 1);
				Nend = new GregorianCalendar(year, 11, 31);
				
				System.out.println("년:"+Nstart.getTime());
				aAbeanB=aAdao.yearList(Integer.parseInt(request.getParameter("list")),Nstart.getTime(),Nend.getTime());
				
				for(int i = 0; i<aAbeanB.length ; i++){
					System.out.println("몇명:"+aAbeanB[i].getCount());
					System.out.println("날짜별:"+aAbeanB[i].getMem_Date());
				}
					if(aAbeanB.length == 0){
						out.println( "<script>" );
						out.println( "alert(\"選ばれた年には加入された会員がいません!\");" );
						out.println( "location.href=\"/KOMORIUTA/AdminAce.do?action_code=memList&num=1\";" );
						out.println( "</script>" );
						break;
					}else
						request.setAttribute("list",aAbeanB);
						request.setAttribute("page","/Manage/Man_Chart");
						view = request.getRequestDispatcher("/Main/admin/Ad_Main.jsp");
						view.forward(request, response);
				break;
				
			case 3:	
					System.out.println("*****월별차트목록 만들어보세!!*****");
					String Myear = request.getParameter("year");
					String month = request.getParameter("month");
					
					System.out.println("선택 년도:"+Myear);
					System.out.println("선택달:"+month);
					System.out.println("선택 종류:"+request.getParameter("list"));
					
					
					aAbeanB=aAdao.monthList(Integer.parseInt(request.getParameter("list")), Myear, month);
					
					for(int i = 0; i<aAbeanB.length ; i++){
						System.out.println("몇명:"+aAbeanB[i].getCount());
						System.out.println("날짜별:"+aAbeanB[i].getMem_Date());
					}
						if(aAbeanB.length == 0){
							out.println( "<script>" );
							out.println( "alert(\"選ばれた月には加入された会員がいません!\");" );
							out.println( "location.href=\"/KOMORIUTA/AdminAce.do?action_code=memList&num=1\";" );
							out.println( "</script>" );
							break;
						}else
							request.setAttribute("list",aAbeanB);
							request.setAttribute("page","/Manage/Man_Chart");
							view = request.getRequestDispatcher("/Main/admin/Ad_Main.jsp");
							view.forward(request, response);
					break;
			
			}
	}else if(action_code.equals("receptList")){
		System.out.println("*****접수통계리스트*****");
		String numMode = request.getParameter("num");
		int start = numMode != null ? Integer.parseInt(numMode) : -1;
		
			switch(start){
			case 1:
				System.out.println("*****페이지 이동*****");
				request.setAttribute("page","/Manage/Man_RecChart");
				view = request.getRequestDispatcher("/Main/admin/Ad_Main.jsp");
				view.forward(request, response);
				break;
				
			case 2:
				System.out.println("*****년별 접수건수*****");
				
				if(request.getParameter("level").equals("1")){
					System.out.println("할배/할배 년별 접수현황");
					aAbeanB=aAdao.ReYearList(request.getParameter("year"));
						if(aAbeanB.length == 0){
						out.println( "<script>" );
						out.println( "alert(\"選ばれた年には受け付けられた件がありません!\");" );
						out.println( "location.href=\"/KOMORIUTA/AdminAce.do?action_code=receptList&num=1\";" );
						out.println( "</script>" );
						break;
						}else
						request.setAttribute("list",aAbeanB);
						request.setAttribute("page","/Manage/Man_RecChart");
						view = request.getRequestDispatcher("/Main/admin/Ad_Main.jsp");
						view.forward(request, response);
						break;
				
				}else if(request.getParameter("level").equals("2")){
					
					System.out.println("할배/할매 월별접수현황");
					System.out.println("*****월별차트목록 만들어보세!!*****");
					
					String Myear = request.getParameter("year");
					String month = request.getParameter("month");
					
					System.out.println("선택 년도:"+Myear);
					System.out.println("선택달:"+month);
					
					aAbeanB=aAdao.monthRecList(Myear, month);
					
					if(aAbeanB.length == 0){
					
					out.println( "<script>" );
					out.println( "alert(\"選ばれた月には受け付けられた件がありません!\");" );
					out.println( "location.href=\"/KOMORIUTA/AdminAce.do?action_code=receptList&num=1\";" );
					out.println( "</script>" );
					
					break;
					
					}else
					request.setAttribute("list",aAbeanB);
					request.setAttribute("page","/Manage/Man_RecChart");
					view = request.getRequestDispatcher("/Main/admin/Ad_Main.jsp");
					view.forward(request, response);
					break;
				}
				
			case 3:
				System.out.println("젊은애들 년별 접수현황");
				
				aAbeanB=aAdao.ReYearYList(request.getParameter("year"));
				if(aAbeanB.length == 0){
					out.println( "<script>" );
					out.println( "alert(\"選ばれた年には受け付けられた件がありません!!\");" );
					out.println( "location.href=\"/KOMORIUTA/AdminAce.do?action_code=receptList&num=1\";" );
					out.println( "</script>" );
					break;
					}else
					request.setAttribute("list",aAbeanB);
					request.setAttribute("page","/Manage/Man_RecChart");
					view = request.getRequestDispatcher("/Main/admin/Ad_Main.jsp");
					view.forward(request, response);
					break;
			
			case 4:
				System.out.println("젊은애들 월별 접수현황");
				
				aAbeanB=aAdao.monthRecYList(request.getParameter("year"),request.getParameter("month"));
				
				if(aAbeanB.length == 0){
					
					out.println( "<script>" );
					out.println( "alert(\"選ばれた月には受け付けられた件がありません!\");" );
					out.println( "location.href=\"/KOMORIUTA/AdminAce.do?action_code=receptList&num=1\";" );
					out.println( "</script>" );
					
					break;
					
					}else
					request.setAttribute("list",aAbeanB);
					request.setAttribute("page","/Manage/Man_RecChart");
					view = request.getRequestDispatcher("/Main/admin/Ad_Main.jsp");
					view.forward(request, response);
					break;
			}
		
	}
}
}

